using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{	
	private bool bandera = true;

	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{Build ();}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{	Application.Quit ();
		a.RetVal = true;
	}
	protected virtual void cero_click (object sender, System.EventArgs e)
	{anadir("0");}
	protected virtual void uno_click (object sender, System.EventArgs e)
	{anadir("1");}
	protected virtual void dos_click (object sender, System.EventArgs e)
	{anadir("2");}
	protected virtual void tres_click (object sender, System.EventArgs e)
	{anadir("3");}
	protected virtual void cuatro_click (object sender, System.EventArgs e)
	{anadir("4");}
	protected virtual void cinco_click (object sender, System.EventArgs e)
	{anadir("5");}
	protected virtual void seis_click (object sender, System.EventArgs e)
	{anadir("6");}
	protected virtual void siete_click (object sender, System.EventArgs e)
	{anadir("7");}
	protected virtual void ocho_click (object sender, System.EventArgs e)
	{anadir("8");}
	protected virtual void nueve_click (object sender, System.EventArgs e)
	{anadir("9");}
	protected virtual void suma_click (object sender, System.EventArgs e)
	{anadir("+");}
	protected virtual void resta_click (object sender, System.EventArgs e)
	{anadir("-");}
	protected virtual void multi_click (object sender, System.EventArgs e)
	{anadir("x");}
	protected virtual void division_click (object sender, System.EventArgs e)
	{anadir("/");}
	protected virtual void igual_click (object sender, System.EventArgs e)
	{anadir("=");}
	protected virtual void punto_click (object sender, System.EventArgs e)
	{anadir(".");}	

/*-----------------------------------------Aquí los métodos---------------------------*/

	
	public void anadir(string dato){
		if( (dato=="+") || (dato=="-") || (dato=="x") || (dato=="/") || (dato=="=")){	
			operacion(dato);
			return;
		}
		if((edit.Text=="0") || bandera){
			edit.Text=dato;
			bandera=false;
		}
		else
			edit.Text+=dato;			
	}

	public void operacion(string op){ 
		double dato1=double.Parse(edit.Text);
		
		if (label.Text== ""){
			label.Text=edit.Text;
			bandera=true;
		
			if(op != "=") 
				opera.Text=op;
			return;
		}
		 
		bandera=true;
		double dato2=double.Parse(label.Text);
		string operador="";
		
		if(op=="=")
			operador=opera.Text;
		else
			operador=op;
	
	
		switch(operador)
		{
		case "+": dato2+=dato1; 
			break;
		case "-": dato2-=dato1;
			break;
		case "x": dato2*=dato1;
			break;
		case "/": dato2/=dato1;
			break;
		}
		label.Text=dato2.ToString();
		
		if(op=="="){
	 		opera.Text="";
	    	edit.Text=label.Text;
		    label.Text="";
		}
		else opera.Text= operador;
	}
}